
import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Abahe
 */
public class ScreenThree extends GameCanvas implements Runnable {

    private MobileMonstersMIDlet midlet;
    private LayerManager lmgr;
    private boolean running = false;
    private Sprite spBackground;

    public ScreenThree(MobileMonstersMIDlet midlet) {
        super(false);
        setFullScreenMode(true);

        this.midlet = midlet;

        try {
            spBackground = new Sprite(Image.createImage("/screenshoot.png"));

            // create and add to layer manager
            lmgr = new LayerManager();
            lmgr.append(spBackground);
            
        } catch (IOException e) {
        }

    }

    public void start() {
        running = true;
        Thread t = new Thread(this);
        t.start();
    }

    public void run() {
        Graphics g = getGraphics();

        while (running) {
            // look for keypress
            //checkForKeys();
            drawDisplay(g);
            /*
            if (checkForCollision() == false) {
            drawDisplay(g);
            } else {
            //flash backlight and vibrate device
            midlet.display.flashBacklight(500);
            midlet.display.vibrate(500);
            }
             *
             */

            try {
                Thread.sleep(50);
            } catch (InterruptedException ie) {
            }
        }
    }

    private void drawDisplay(Graphics g) {
        //clear background
        g.setColor(0xffffff);
        g.fillRect(0, 0, getWidth(), getHeight());

        g.setColor(0x0000ff);
        g.drawString("Screen One", 100, 20, Graphics.TOP | Graphics.LEFT);

        //animated sprite, show next frame in sequence
        //spSpiral.nextFrame();

        //paint all layers
        lmgr.paint(g, 0, 0);

        //flush off-screen buffer to display
        flushGraphics();
    }

    public void stop() {
        running = false;
    }

    protected void keyPressed(int keyCode) {
        if (keyCode == -5) {
        } else if (keyCode == -2) { //down
        } else if (keyCode == -4) { //right
            System.out.println("three : " + MobileMonstersMIDlet.CLICKED);
            if (MobileMonstersMIDlet.CLICKED < 1) {
                MobileMonstersMIDlet.CLICKED++;
                midlet.beforeShow(3);
            }
        } else if (keyCode == -1) { //up
        } else if (keyCode == -3) { //left
        } else if (keyCode == -7) {
            midlet.exit();
        } else if (keyCode == -6) {
        }
    }
}
